package machine;

import static machine.InstructionFunctions.*;

public class Instruction {
	InstructionName op;
	Object r, n, d;
	
	public Instruction(InstructionName op) {
		this.op = op;
	}
	
	public Instruction(InstructionName op, Object r, Object n, Object d) {
		this.op	= op;
		this.r 	= r;
		this.n	= n;
		this.d	= d;
	}
	
	public void replace(String key, int value) {
		if ((r instanceof String) && ((String)r).equals(key)) {
			r = value;
		}
		if ((n instanceof String) && ((String)n).equals(key)) {
			n = value;
		}
		if ((d instanceof String) && ((String)d).equals(key)) {
			d = value;
		}
	}

	public boolean hasString() {
		return ((r instanceof String) || (n instanceof String) || (d instanceof String));
	}
	
	public String toString() {
		return op + "\t" + r + "\t" + n + "\t" + d;
	}
}